<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="ccnp,">










<meta name="description" content="为什么使用路由迁徙： 网络规模扩大，路由协议受限，地址的迁徙等。  ＜路由协议的迁移＞ 当网络中原有的路由协议不能再很好的满足需求的时候，就需要转换为另一种路由协议，这就需要进行路由协议的迁移。  路由迁移的原则：  1. 尽可能少的减少网络的停工时间   2. 做好回退准备，一旦在迁移过程中出了问题，要能迅速回退到初始状态 （rollback）  3. 在迁移过程中要避免出现路由黑洞和环路，次优">
<meta name="keywords" content="ccnp">
<meta property="og:type" content="article">
<meta property="og:title" content="ccnp_重分布">
<meta property="og:url" content="https://srat1999.top/2019/04/01/ccnp-重分布/index.html">
<meta property="og:site_name" content="Stay hungry stay foolish">
<meta property="og:description" content="为什么使用路由迁徙： 网络规模扩大，路由协议受限，地址的迁徙等。  ＜路由协议的迁移＞ 当网络中原有的路由协议不能再很好的满足需求的时候，就需要转换为另一种路由协议，这就需要进行路由协议的迁移。  路由迁移的原则：  1. 尽可能少的减少网络的停工时间   2. 做好回退准备，一旦在迁移过程中出了问题，要能迅速回退到初始状态 （rollback）  3. 在迁移过程中要避免出现路由黑洞和环路，次优">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_1.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_2.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_3.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_4.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_5.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_6.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_7.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_8.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_10.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_11.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_12.png">
<meta property="og:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_13.png">
<meta property="og:updated_time" content="2019-11-30T04:21:13.553Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ccnp_重分布">
<meta name="twitter:description" content="为什么使用路由迁徙： 网络规模扩大，路由协议受限，地址的迁徙等。  ＜路由协议的迁移＞ 当网络中原有的路由协议不能再很好的满足需求的时候，就需要转换为另一种路由协议，这就需要进行路由协议的迁移。  路由迁移的原则：  1. 尽可能少的减少网络的停工时间   2. 做好回退准备，一旦在迁移过程中出了问题，要能迅速回退到初始状态 （rollback）  3. 在迁移过程中要避免出现路由黑洞和环路，次优">
<meta name="twitter:image" content="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://srat1999.top/2019/04/01/ccnp-重分布/">





  <title>ccnp_重分布 | Stay hungry stay foolish</title>
  








<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Stay hungry stay foolish</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">srat1999's blog</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://srat1999.top/2019/04/01/ccnp-重分布/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="srat1999">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/pikachu.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Stay hungry stay foolish">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">ccnp_重分布</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-04-01T19:05:54+08:00">
                2019-04-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ccnp/" itemprop="url" rel="index">
                    <span itemprop="name">ccnp</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3.1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  13
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="为什么使用路由迁徙："><a href="#为什么使用路由迁徙：" class="headerlink" title="为什么使用路由迁徙："></a>为什么使用路由迁徙：</h2><p>网络规模扩大，路由协议受限，地址的迁徙等。</p>
<p>＜路由协议的迁移＞<br>当网络中原有的路由协议不能再很好的满足需求的时候，就需要转换为另一种路由协议，这就需要进行路由协议的迁移。</p>
<h2 id="路由迁移的原则："><a href="#路由迁移的原则：" class="headerlink" title="路由迁移的原则："></a>路由迁移的原则：</h2><ol>
<li>尽可能少的减少网络的停工时间   </li>
<li>做好回退准备，一旦在迁移过程中出了问题，要能迅速回退到初始状态 （rollback）</li>
<li>在迁移过程中要避免出现路由黑洞和环路，次优路径等问题</li>
</ol>
<h2 id="路由迁移过程："><a href="#路由迁移过程：" class="headerlink" title="路由迁移过程："></a>路由迁移过程：</h2><ol>
<li>将原有协议的AD值改小</li>
<li>在现在网络上配置新的路由协议</li>
<li>将原有协议的AD值再改大，让新协议的路由起作用</li>
<li>如果路由正常，删除原有协议</li>
</ol>
<p>==路由协议的重分布==</p>
<p>定义：重分布是指连接到不同路由选择域的边界路由器在不同自主系统之间交换和通告路由选择信息的能力。</p>
<p><strong>重分布原则</strong>：路由必须位于路由选择表中才能被重分发</p>
<hr>
<p>==<strong>在重分发时设定种子metric</strong>==</p>
<p><strong>协议</strong>——————-<strong>Seed Metric</strong><br>RIP——————-无限大    必须手工指定 (直连静态默认是1)<br>EIGRP—————无限大    也必须手工指定（直连静态自动计算）<br>OSPF—————-20    如果重分布进来的是BGP的话，Metric是1，这是个特例<br>IS-IS         —————-0<br>BGP—————–携带原来的Metric值</p>
<hr>
<h2 id="重分布分两种："><a href="#重分布分两种：" class="headerlink" title="重分布分两种："></a>重分布分两种：</h2><p>1、单向重分布<br>2、双向重分布</p>
<p>1）OSPF -&gt; RIP：<br>　将其它路由协议重分布进RIP，要注意加metric值<br>　<img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_1.png" alt="enter description here"><br>2）RIP -&gt; OSPF：　<br>  将其它路由协议重分布进OSPF，要注意加==subnets==参数<br>  <img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_2.png" alt="enter description here"><br>3）OSPF—〉EIGRP<br>＜单点双向重分布时的汇总路由回馈问题＞<br>  <img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_3.png" alt="enter description here"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">redistribute ospf 110 metric 10000 100 255 1 1500</span><br></pre></td></tr></table></figure>
<p>将其他协议重分布进==eigrp==的时候必须带上metric参数，这五个参数分别是指bangwidth、delay、reliability、loading、MTU</p>
<hr>
<p>实验：<br>1、在R1上将OSPF重分布进EIGRP<br>2、在R1的S1/0接口做EIGRP的手动汇总，汇总出一条172.16.0.0/16路由。这时R2将只收到一条汇总路由。<br>3、再在R1上将EIGRP重分布进OSPF</p>
<p><strong>这时你会发现，R3上除了正常收到12.1.1.0的路由之外，还多了一条汇总路由，因为在R1上做了汇总之后，生成了一条指向NULL0接口的汇总路由，这样，在把EIGRP重分布进OSPF时，把这条路由也带进去了。</strong></p>
<hr>
<h2 id="经典的重分布试验："><a href="#经典的重分布试验：" class="headerlink" title="经典的重分布试验："></a>经典的重分布试验：</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">试验题：在R1上做三次重分布，先将OSPF重分布进EIGRP，然后将EIGRP重分布进RIP，再将RIP重分布进OSPF，完成后，看看能否实现全网互通。也就是说，3.3.3.3和4.4.4.4，以及2.2.2.2能否互相Ping通。</span><br></pre></td></tr></table></figure>
<p><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_4.png" alt="enter description here"></p>
<p><strong>Router上所有运行A协议的接口（除ISIS/ODR），以及Router路由表中所有从A协议学到的路由，都会被重分布到B协议中。</strong></p>
<hr>
<h2 id="双向双点重分发"><a href="#双向双点重分发" class="headerlink" title="双向双点重分发"></a>双向双点重分发</h2><p><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_5.png" alt="enter description here"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">试验：在R1和R4上先将OSPF重分布进RIP，看看网络会不会出问题，每个路由器的路由表正不正常。</span><br><span class="line">      再在R1和R4上将RIP重分布进OSPF，看看有没有问题。</span><br></pre></td></tr></table></figure>
<p>通过试验，我们总结出：</p>
<ol>
<li>做双点双向重分布时，把AD值低的路由协议重分布进AD值高的路由协议，没啥问题。</li>
<li><strong>==当把AD高的协议重分布到AD低的协议中时，就有可能出现问题==</strong>。</li>
</ol>
<h3 id="解决方法"><a href="#解决方法" class="headerlink" title="解决方法"></a>解决方法</h3><ol>
<li><p>不好的方法–改所有路由的AD【并不能解决双向的问题，只能解决单向分发的问题】</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">R1(config)#router ospf 110</span><br><span class="line">R1(config-router)#distance 171 （将此协议的路由的AD改为171，对本协议所有路由都有效,改动范围太大，通常不建议这样做，而且是有问题的。）</span><br></pre></td></tr></table></figure>
</li>
<li><p>好的方法–缩小范围【比较适合ospf中使用】</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">R1(config-router)#distance 171 4.4.4.4（在OSPF中，这是RID） 0.0.0.0　　（只将路由器4.4.4.4通告的OSPF路由AD改为171）</span><br><span class="line">```　　　　　　　　　　　　　　　  </span><br><span class="line">3. 最好的方法--进一步缩小范围【对多种路由协议都适合，推荐使用】</span><br><span class="line">```R1(config)#access-list 2 permit 2.2.2.0</span><br><span class="line">R1(config-router)#distance 171 4.4.4.4 0.0.0.0 2　（只针对4.4.4.4通告的2.2.2.0路由将AD改为171，对4.4.4.4通告的其它路由AD不变）</span><br><span class="line">R1(config-router)#distance 171  0.0.0.0 255.255.255.255 2【注意0.0.0.0代表所有】</span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>上面这条命令针对所有路由器通告的指定路由来改AD，在这一定要注意通告路由器的概念，在OSPF中和EIGRP中通告的路由器的区别，要注意你所要更改的路由是由哪一个路由器通告的。</p>
<ol start="4">
<li>还可以通过为OSPF设置外部路由的管理距离来解决，只要将外部路由的管理距离增大到超过重分布进来的协议的AD就可以了<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">R4(config-router)#distance ospf external 99 inter-area 88 intra-area 77【适合ospf】</span><br></pre></td></tr></table></figure>
</li>
</ol>
<hr>
<h2 id="＜Distribute-List＞用来过滤路由"><a href="#＜Distribute-List＞用来过滤路由" class="headerlink" title="＜Distribute-List＞用来过滤路由"></a>＜Distribute-List＞用来过滤路由</h2><p><strong>==分布列表通过调用ACL来对路由进行过滤，可以在一个单独的路由区域内过滤，也可在路由协议之间做重分布的时候进行过滤==</strong>。<br>注意：分布列表只能用于距离矢量协议，在==链路状态协议==中是没有意义的。</p>
<p>例一：<br><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_6.png" alt="例一"><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">R1(config)#access-list 2 permit 2.2.2.0</span><br><span class="line">R1(config-router)#distribute-list 2 in serial 0 （只允许2.2.2.0路由从S0进）</span><br></pre></td></tr></table></figure></p>
<p>例二：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">R1(config)#access-list 2 deny 2.2.2.0</span><br><span class="line">R1(config)#access-list 2 permit any </span><br><span class="line">R1(config-router)#distribute-list 2 out serial 1 （不允许2.2.2.0路由从S1接口出去）</span><br></pre></td></tr></table></figure></p>
<p>例三：协议间重分布时过滤<br><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_7.png" alt="例三"><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">R1(config)#access-list 1 permit 2.2.2.0 </span><br><span class="line">R1(config)#router ospf 110</span><br><span class="line">R1(config-router)#distribute-list 1 out eigrp 90</span><br></pre></td></tr></table></figure></p>
<p><strong>注意：当在重分布时进行过滤，仅允许使用关键字out，后面可以跟上协议名，但不能跟接口，因为无意义，详见卷一496页（注意：in后面不能跟协议，只有out后能跟）</strong></p>
<h2 id="＜Prefix-List＞前缀列表"><a href="#＜Prefix-List＞前缀列表" class="headerlink" title="＜Prefix-List＞前缀列表"></a>＜Prefix-List＞前缀列表</h2><p>和ACL类似的东东，设计用于专抓路由的工具，不仅可以匹配网络号，还可以匹配掩码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">R4(config)#ip prefix-list 2（用名字也行） permit 2.2.2.0/24</span><br><span class="line">R4(config-router)#distribute-list prefix 2 in serial 1</span><br></pre></td></tr></table></figure></p>
<p>例一：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip prefix-list 2 permit 2.2.2.0/24　　　　　　　//（匹配前24位:2.2.2.* ，掩码必须为24位）</span><br></pre></td></tr></table></figure></p>
<p>例二：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip prefix-list 2 permit 2.2.2.0/24 ge 25 le 30　//（匹配前24位:2.2.2.* ，掩码必须为25-30位）</span><br></pre></td></tr></table></figure></p>
<p>例三：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip prefix-list 2 permit 2.2.2.0/24 le 32　　　　//（匹配前24位:2.2.2.* ，掩码必须为24-32位）</span><br></pre></td></tr></table></figure></p>
<p>例四：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip prefix-list 2 permit 2.2.2.0/24 ge 26　　　　//（匹配前24位:2.2.2.* ，掩码必须为26-32位）</span><br></pre></td></tr></table></figure></p>
<p>例五：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ip prefix-list 3 permit 0.0.0.0/0 le 32　　　　 //（匹配所有）不能像access-list哪样用any参数</span><br></pre></td></tr></table></figure></p>
<p>==ge必须大于前面的数字，小或等于le ,len&lt;ge-value&lt;=le-value==<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sh ip prefix-list用于查看</span><br></pre></td></tr></table></figure></p>
<p><strong>用前缀列表过滤A、B、C类路由:</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">A类路由：ip prefix-list 1 permit 0.0.0.0/1 le 32</span><br><span class="line">B类路由：ip prefix-list 1 permit 128.0.0.0/2 le 32</span><br><span class="line">C类路由：ip prefix-list 1 permit 192.0.0.0/3 le 32</span><br><span class="line">默认路由                         0.0.0.0/0</span><br><span class="line">所有路由                         0.0.0.0/0 le 32</span><br><span class="line">除了默认路由以外的所有路由        0.0.0.0/0 ge 1</span><br></pre></td></tr></table></figure></p>
<h3 id="利用前缀列表过滤OSPF"><a href="#利用前缀列表过滤OSPF" class="headerlink" title="利用前缀列表过滤OSPF"></a>利用前缀列表过滤OSPF</h3><p><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_8.png" alt><br>要求：在如上图所示的拓朴中，在R1上利用前缀列表做过滤，不要向AREA0区域传递172.16.1.1的路由。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">R1：</span><br><span class="line"></span><br><span class="line">ip prefix-list 1 seq 5 deny 172.16.1.1/32</span><br><span class="line">ip prefix-list 1 seq 10 permit 0.0.0.0/0 le 32</span><br><span class="line"></span><br><span class="line">router ospf 110</span><br><span class="line">  area 1 filter-list prefix 1 out</span><br></pre></td></tr></table></figure></p>
<h2 id="＜Route-Map＞"><a href="#＜Route-Map＞" class="headerlink" title="＜Route-Map＞"></a>＜Route-Map＞</h2><p>也叫路由图或者路由映射表，是对路由进行加工处理的工具。</p>
<p>1、route-map可以调用ACL或prefix抓出一部分路由进行加工处理<br>2、每一个route-map可以有多条语句，每条语句都有一个序号<br>3、每条语句都有两种动作：match 和 set<br>4、每条语句对抓出来的路由都有两种处理方式：permit 或 deny</p>
<p><strong>route-map的使用分三步操作</strong>：<br>1、定义ACL或prefix抓出路由<br>2、定义route-map说明对匹配的路由所采取的处理方式<br>3、调用route-map</p>
<p><strong>route-map的匹配逻辑：</strong><br>route-map NAME permit 10<br> match ip address x y z<br>                 ——-&gt; OR<br> match ip address a  ￤<br> match ip address b  ￤ AND<br> match ip address c  ↓</p>
<p>==如不写match/set,默认：  match any<br>                       set   nothing==</p>
<p><strong>例一：</strong></p>
<p>要求在R1上将EIGRP重分布进OSPF，其中172.16.1.0路由要以OE1重分布，172.16.2.0路由重分布时metric值要改为100，172.16.3.0的路由不允许重分布，其它路由不改动，默认重分布。<br><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_10.png" alt><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">R1(config)#access-list 1 permit 172.16.1.0 0.0.0.0</span><br><span class="line">R1(config)#access-list 2 permit 172.16.2.0 0.0.0.0</span><br><span class="line">R1(config)#access-list 3 permit 172.16.3.0 0.0.0.0</span><br><span class="line"></span><br><span class="line">R1(config)#route-map Justech permit 10</span><br><span class="line">R1(config-route-map)#match ip address 1</span><br><span class="line">R1(config-route-map)#set metric-type type-1</span><br><span class="line"></span><br><span class="line">R1(config)#route-map Justech permit 20</span><br><span class="line">R1(config-route-map)#match ip address 2</span><br><span class="line">R1(config-route-map)#set metric 100</span><br><span class="line"></span><br><span class="line">R1(config)#route-map Justech deny 30</span><br><span class="line">R1(config-route-map)#match ip address 3</span><br><span class="line"></span><br><span class="line">R1(config)#route-map Justech permit 40</span><br><span class="line">R1(config-route-map)#exit</span><br><span class="line"></span><br><span class="line">R1(config)#router ospf 110</span><br><span class="line">R1(config-router)#redistribute eigrp 90 subnets route-map Justech   //调用route-map</span><br></pre></td></tr></table></figure></p>
<p>==注意：<br>·在route-map的最后隐含了一条deny any的语句<br>·如果不写一句空Route-map 去允许其它路由通过，则没有匹配的路由直接被丢弃。==</p>
<p><strong>例二：match 接口</strong><br>还可以在重分布直连的时候match一个接口，直接写route-map就可以，不用定义访问列表。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">R1(config)#route-map Justech permit 10</span><br><span class="line">R1(config-route-map)#match interface e0</span><br></pre></td></tr></table></figure></p>
<p><strong>例三：使用route-map打tag</strong></p>
<p>作用：可以对一些路由打上tag，好让后面的路由器根据tag找出这些路由并进行相应的策略<br><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_11.png" alt><br>如上图所示，要求：<br>1、在R3上将RIP重分布进OSPF<br>2、在R1上将OSPF重分布进EIGRP，但不能将从RIP学到的路由带过去</p>
<p>可以用tag解决：<br>1、在R3上将RIP重分布进OSPF时，利用route-map打上tag标记<br>2、在R1上将OSPF重分布进EIGRP时，找出打了tag标记的路由再deny掉就行了<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">R3(config)#route-map Justech permit 10</span><br><span class="line">R3(config-route-map)#set tag 20</span><br><span class="line"></span><br><span class="line">R3(config)#router ospf 110</span><br><span class="line">R3(config-router)#redistribute rip subnets route-map Justech</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">到了R1之后，对打tag的路由丢弃</span><br><span class="line">R1(config)#route-map CCNP deny 10</span><br><span class="line">R1(config-route-map)#match tag 20</span><br><span class="line">R1(config)#route-map CCNP permit 20    //一定要写一条空语句放行其它的路由</span><br><span class="line">R1(config-route-map)#exit</span><br><span class="line"></span><br><span class="line">R1(config)#router eigrp 90</span><br><span class="line">R1(config-router)#redistribute ospf 110 metric 1500 100 255 1 1500 route-map CCNP</span><br></pre></td></tr></table></figure></p>
<h3 id="＜Policy-Based-Routing＞"><a href="#＜Policy-Based-Routing＞" class="headerlink" title="＜Policy-Based Routing＞"></a>＜Policy-Based Routing＞</h3><p>PBR就是使用route-map这一工具对某个接口进来的数据流做一些策略，符合条件的按相应的策略进行路由，不符合条件的按正常情况进行转发。</p>
<p><strong>PBR的规则</strong>：<br>· PBR allows for source-based routing.</p>
<p>· ==PBR优于路由表==—–如果路由器上设置了PBR，当数据包到达路由器时，是先匹配PBR，如果匹配上了，直接按PBR进行转发，如果没匹配上，再去找路由表进行转发，所以说PBR覆盖了正常的路由选择进程。</p>
<p>·==PBR中不匹配的数据包不会DENY（丢弃），而是normal forwarding(正常转发)==</p>
<p><strong>注意：　Applied to incoming packets PBR只针对于入项接口</strong></p>
<p><strong>例一：</strong><br><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_12.png" alt><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">第一步：</span><br><span class="line">R1(config)#access-list 1 permit 1.1.1.0 0.0.0.255</span><br><span class="line">R1(config)#access-list 2 permit 2.2.2.0 0.0.0.255</span><br><span class="line"></span><br><span class="line">第二步：</span><br><span class="line">R1(config)#route-map pbr permit 10</span><br><span class="line">R1(config-route-map)#match ip address 1</span><br><span class="line">R1(config-route-map)#set ip next-hop 12.1.1.2 发给与本机直连的下一跳路由器</span><br><span class="line"></span><br><span class="line">R1(config)#route-map pbr permit 20</span><br><span class="line">R1(config-route-map)#match ip address 2</span><br><span class="line">R1(config-route-map)#set ip next-hop 13.1.1.3 </span><br><span class="line"></span><br><span class="line">第三步：</span><br><span class="line">R1(config)#int e0/0 　(入口调用策略）</span><br><span class="line">R1(config-if)#ip policy route-map pbr</span><br></pre></td></tr></table></figure></p>
<p><strong>PBR其它用途</strong>：</p>
<p>R1(config)#route-map pbr per 10<br>R1(config-route-map)#match ip address 9<br>R1(config-route-map)#set ip precedence 2 对数据分组设置优先级</p>
<p>R3#debug ip policy </p>
<p><strong>本地策略路由：</strong>　　　　　　　　　　　　　　　　　　　　<br>·PBR默认对本地产生的数据流量不起效。也就是对自已产生的包不执行策略。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">R3(config)#ip local policy route-map PBR　（使PBR对本地数据流量有效）加上这一条命令才会对自已产生的包也做策略</span><br></pre></td></tr></table></figure></p>
<p><strong>实验：</strong><br><img src="https://raw.githubusercontent.com/srat1999/Pictures/master/img/重分布_13.png" alt></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/ccnp/" rel="tag"># ccnp</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/03/31/湖光山色曲/" rel="next" title="湖光山色曲">
                <i class="fa fa-chevron-left"></i> 湖光山色曲
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/04/11/Feistel加密算法/" rel="prev" title="Feistel加密算法">
                Feistel加密算法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/pikachu.jpg" alt="srat1999">
            
              <p class="site-author-name" itemprop="name">srat1999</p>
              <p class="site-description motion-element" itemprop="description">the higher you stand the more you can see</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">55</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">30</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/srat1999" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:srat1999@163.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么使用路由迁徙："><span class="nav-number">1.</span> <span class="nav-text">为什么使用路由迁徙：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#路由迁移的原则："><span class="nav-number">2.</span> <span class="nav-text">路由迁移的原则：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#路由迁移过程："><span class="nav-number">3.</span> <span class="nav-text">路由迁移过程：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#重分布分两种："><span class="nav-number">4.</span> <span class="nav-text">重分布分两种：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#经典的重分布试验："><span class="nav-number">5.</span> <span class="nav-text">经典的重分布试验：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#双向双点重分发"><span class="nav-number">6.</span> <span class="nav-text">双向双点重分发</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#解决方法"><span class="nav-number">6.1.</span> <span class="nav-text">解决方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#＜Distribute-List＞用来过滤路由"><span class="nav-number">7.</span> <span class="nav-text">＜Distribute-List＞用来过滤路由</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#＜Prefix-List＞前缀列表"><span class="nav-number">8.</span> <span class="nav-text">＜Prefix-List＞前缀列表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#利用前缀列表过滤OSPF"><span class="nav-number">8.1.</span> <span class="nav-text">利用前缀列表过滤OSPF</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#＜Route-Map＞"><span class="nav-number">9.</span> <span class="nav-text">＜Route-Map＞</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#＜Policy-Based-Routing＞"><span class="nav-number">9.1.</span> <span class="nav-text">＜Policy-Based Routing＞</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">srat1999</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">70.1k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







  <div>
    <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1278555274'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s4.cnzz.com/z_stat.php%3Fid%3D1278555274%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>
    <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? "https://" : "http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1278555274'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s4.cnzz.com/z_stat.php%3Fid%3D1278555274%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));</script>
  </div>
 



        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
